<template>
  <div>
    <el-table
      :data="catelist"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号"> </el-table-column>
      <el-table-column prop="catename" label="分类名称"> </el-table-column>
      <el-table-column label="图片"> 
        <template slot-scope="scope">
          <div>
            <img :src="$pre+scope.row.img" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if='scope.row.status==1'>启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.id)">编辑</el-button>
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
import {mapActions,mapGetters} from 'vuex'
import {catedelete} from '../../../request/api'
import { successAlert, warningAlert } from "../../../util/alert";
export default {
  data() {
    return {
      tableData: [
        {
          id: 1,
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          id: 2,
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          id: 3,
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
          children: [
            {
              id: 31,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
            {
              id: 32,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
          ],
        },
        {
          id: 4,
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  methods:{
    ...mapActions({
      reqcatelist:'cate/reqchangelist'
    }),
    // 点击编辑
    bianji(id){
      this.$emit("bianji",id)
    },
    // 点击删除
    del(id){
      // console.log(id);
      catedelete({id:id}).then(res=>{
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          // 刷新数据
          this.reqcatelist()
        } else {
          warningAlert(res.data.msg);
        }
      })
    }
  },
  computed:{
    ...mapGetters({
      catelist:'cate/list'
    })
  }
};
</script>

<style scoped>
img{
  width: 100px;
  height: 100px;
}
</style>